local ffi = require("ffi")
local bit = require("bit")

--[[
=======================
 C lib register
=======================
]]

--wiring pi
ffi.cdef[[
    //setup
    int wiringPiSetup (void);
    int wiringPiSetupGpio(void);
    int wiringPiSetupPhys(void);

   //core 
    void pinMode(int pin, int mod);
    void pwmWrite (int pin, int value);
    
    void digitalWrite (int pin, int value);
    int digitalRead (int pin);

    int analogRead (int pin);
    void analogWrite(int pin , int value);

    //timing
    void delayMicroseconds (unsigned int howLong);
]]


--c_extend 
ffi.cdef[[
    int sleep(int sec);
    void delay(unsigned int msec);
    int test();
]]

local pilib = ffi.load("libs/pilib.so")



--[[
=======================
const
=======================
]]

--[[ Pin modes

#define	INPUT			 0
#define	OUTPUT			 1
#define	PWM_OUTPUT		 2
#define	GPIO_CLOCK		 3
#define	SOFT_PWM_OUTPUT		 4
#define	SOFT_TONE_OUTPUT	 5
#define	PWM_TONE_OUTPUT		 6

#define	LOW			 0
#define	HIGH			 1
]]
_G.PIN_MODE = {}
PIN_MODE.INPUT = 0
PIN_MODE.OUTPUT = 1
PIN_MODE.PWM_OUTPUT = 2
PIN_MODE.GPIO_CLOCK = 3
PIN_MODE.SOFT_PWM_OUTPUT = 4
PIN_MODE.SOFT_TONE_OUTPUT = 5

PIN_MODE.LOW = 0
PIN_MODE.HIGH = 1



return pilib
